



//display job detail
(function() {
	Titanium.include(Ti.App.Properties.getString('base_folder_name')
			+ 'helloweb.js');
	var win = Titanium.UI.currentWindow;
	var barcode_scan_page_obj = null;

	function barcode_scan_page() {
		var self = this;
		var window_source = 'barcode_scan_page';
		win.title = 'Scan Barcode';

		// public method
		/**
		 * override init function of parent class: fieldteam.js
		 */
		self.init = function() {
			try {
				self.init_auto_release_pool(win);
				self.data = [];
				// call init_navigation_bar function of parent class:
				// fieldteam.js

				self.init_navigation_bar('Close', '');

				self.init_vars();
				_scan_barcode();
			} catch (err) {
				self.process_simple_error_message(err, window_source
						+ ' - self.init');
				return;
			}
		};

		/**
		 * override nav_right_btn_click_event function of parent class:
		 * fieldteam.js
		 */
		self.nav_right_btn_click_event = function(e) {
			try {
				self.close();

			} catch (err) {
				self.process_simple_error_message(err, window_source
						+ ' - self.nav_right_btn_click_event');
				return;
			}
		};

		// public member
		// self.action_for_job = win.action_for_job;
		var _type = win.type;
		var _selected_job_id = win.job_id;

		/*
		 * open scan barcode window
		 */
		function _scan_barcode() {
			try {
				if (!Ti.Network.online) {
					self.show_message(L('message_offline'),
							L('message_unable_to_connect'));
					return;
				}

				var scanditsdk = require("com.mirasense.scanditsdk");

				// disable the status bar for the camera view on the iphone and
				// ipad
				if (Ti.Platform.osname == 'iphone'
						|| Ti.Platform.osname == 'ipad') {
					Titanium.UI.iPhone.statusBarHidden = true;
				}
				var picker;
				// Create a window to add the picker to and display it.
				var window = Titanium.UI.createWindow({
					title : 'Scan Barcode',
					navBarHidden : true
				});
				// Instantiate the Scandit SDK Barcode Picker view
				picker = scanditsdk.createView({
					width : "100%",
					height : "100%"
				});
				// Initialize the barcode picker, remember to paste your own app
				// key here.
				picker.init(self.scanditsdk_key, 0);

				picker.showSearchBar(false);
				// add a tool bar at the bottom of the scan view with a cancel
				// button (iphone/ipad only)
				picker.showToolBar(true);

				// Set callback functions for when scanning succeedes and for
				// when the
				// scanning is canceled.
				picker.setSuccessCallback(function(e) {
					if (picker != null) {
						picker.stopScanning();
						window.remove(picker);
					}
					window.close();
					self.display_indicator('Searching...', true);
					_search_barcode(e);
				});
				picker.setCancelCallback(function(e) {
					if (picker != null) {
						picker.stopScanning();
						window.remove(picker);
					}
					window.close();
				});

				window.add(picker);
				window.addEventListener('open', function(e) {
					// Adjust to the current orientation.
					// since window.orientation returns 'undefined' on ios
					// devices
					// we are using Ti.UI.orientation (which is deprecated and
					// no longer
					// working on Android devices.)
					if (Ti.Platform.osname == 'iphone'
							|| Ti.Platform.osname == 'ipad') {
						picker.setOrientation(Ti.UI.orientation);
					} else {
						picker.setOrientation(window.orientation);
					}

					picker.setSize(Ti.Platform.displayCaps.platformWidth,
							Ti.Platform.displayCaps.platformHeight);
					picker.startScanning(); // startScanning() has to be called
											// after the window is opened.
				});
				window.open();

				// Changes the picker dimensions and the video feed orientation
				// when the
				// orientation of the device changes.
				// Ti.Gesture.addEventListener('orientationchange', function(e)
				// {
				// window.orientationModes = [Titanium.UI.PORTRAIT,
				// Titanium.UI.UPSIDE_PORTRAIT,
				// Titanium.UI.LANDSCAPE_LEFT, Titanium.UI.LANDSCAPE_RIGHT];
				// if (picker != null) {
				// picker.setOrientation(e.orientation);
				// picker.setSize(Ti.Platform.displayCaps.platformWidth,
				// Ti.Platform.displayCaps.platformHeight);
				// // You can also adjust the interface here if landscape should
				// look
				// // different than portrait.
				// }
				// });
			} catch (err) {
				self.process_simple_error_message(err, window_source
						+ ' - _scan_barcode');
				return;
			}
		}
	}

	win.addEventListener('open', function() {
		try {
			if (barcode_scan_page_obj === null) {
				var F = function() {
				};
				F.prototype = HelloWeb.prototype;
				barcode_scan_page.prototype = new F();
				barcode_scan_page.prototype.constructor = barcode_scan_page;
				barcode_scan_page_obj = new barcode_scan_page();
				barcode_scan_page_obj.init();
			}
		} catch (err) {
			alert(err);
			return;
		}
	});

	win.addEventListener('close', function() {
		try {
			barcode_scan_page_obj.close_window();
			barcode_scan_page_obj = null;
			win = null;
		} catch (err) {
			alert(err);
			return;
		}
	});
}());
